package com.example.service.impl;

import com.example.dto.CommentDTO;
import com.example.mapper.CommentMapper;
import com.example.result.CommonResult;
import com.example.service.CommentService;
import com.example.vo.CommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject："smart-property"
 * @BelongsPackage："com.example.service.impl"
 * @CreateTime："2022-11-14 19:07"
 * @Description：评论
 * @Author：LK
 */
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    /**
     * @description:评论全查、分页、模糊查
     * @author: lk
     * @date: 2022/11/14 19:09
     * @param: commentVO
     * @return: java.util.List<com.example.dto.CommentDTO>
     **/
    @Override
    public CommonResult commentCleck(CommentVO commentVO) {
        Map<String, Object> map = new HashMap<>();
        try{
            // 计算每页数据的开始
            commentVO.setPageNum((commentVO.getPageNum() - 1) * commentVO.getPageSize());
            // 全查数据
            List<CommentDTO> commentDTOS = commentMapper.commentCleck(commentVO);
            // 数据总数
            Integer total = commentMapper.commentCleckTotal(commentVO);
            map.put("msg",commentDTOS);
            map.put("total",total);
            return CommonResult.ok(map);
        }catch (Exception e){
            return CommonResult.fail();
        }
    }

    /**
     * @description:删除评论
     * @author: lk
     * @date: 2022/11/15 9:55
     * @param: commentNumber
     * @return: com.example.result.CommonResult
     **/
    @Override
    public CommonResult commentDel(String commentNumber) {
        Integer i = commentMapper.commentDel(commentNumber);
        if(i > 0){
            return CommonResult.ok();
        }
        return CommonResult.fail();
    }
}
